﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Delonix_Regia_Hotel_Management_System.Classes;

namespace Delonix_Regia_Hotel_Management_System
{
    public partial class BookingPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Session["user"] == null)
                {
                    Response.Redirect("LoginPage.aspx");
                }
            }

            tbxRoomnum.Text = Session["RoomNum"].ToString();
            tbxRoomtype.Text = Session["RoomType"].ToString();
            tbxSmokingroom.Text = Session["SmokingRoom"].ToString();
        }

        protected void btnBook_Click(object sender, EventArgs e)
        {
            string first_name = tbxFirstname.Text;
            string last_name = tbxLastname.Text;
            string phone_num = tbxPhonenum.Text;
            string email = tbxEmail.Text;
            string check_in_date = tbxCheckindate.Text;
            string check_out_date = tbxCheckoutdate.Text;
            string check_in_time = tbxCheckintime.Text;
            string check_out_time = tbxCheckouttime.Text;
            string adult = tbxAdult.Text;
            string child = tbxChild.Text;
            string home_address = tbxHomeaddress.Text;
            string mailing_address = tbxMailingaddress.Text;
            string postal_code = tbxPostalcode.Text;
            string room_type = tbxRoomtype.Text;
            string bed_sizes = tbxBedsizes.Text;
            string smoking_room = tbxSmokingroom.Text;
            string credit_card_info = tbxCreditcardnum.Text;
            string room_num = tbxRoomnum.Text;
            string check_in_by = tbxCheckinby.Text;
            string total_bill = tbxTotalbill.Text;
            string housekeeper_name = ddlHousekeeper.Text;

            HotelGuest g = new HotelGuest(first_name, last_name, phone_num, email, check_in_date, check_out_date, check_in_time, check_out_time, adult, child, home_address, mailing_address, postal_code, room_type, bed_sizes, smoking_room, credit_card_info, room_num, check_in_by, total_bill, housekeeper_name);
            int rowsreturned = DBManager.createGuest(g);

            if (rowsreturned > 0)
                lblStatus.Text = "Book-In Successful!";

            Room r = new Room();
            r = DBManager.GetRoomByRoomNo(tbxRoomnum.Text);
            r.Yearly_statistics++;
            r.Monthly_statistics++;
            DBManager.updateRoom(r);
        }

        protected void btnLogo_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("WelcomePage.aspx");
        }

        protected void btnAdmin_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("AdminMainPage.aspx");
        }

        protected void btnCheckIn_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("CheckInPage.aspx");
        }

        protected void btnCheckOut_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("CheckOutPage.aspx");
        }

        protected void btnQuery_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("QueryPage.aspx");
        }

        protected void btnBooking_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("RoomAvailabilityPage.aspx");
        }

        protected void btnRates_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("RatesPage.aspx");
        }

        protected void btnStaff_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("StaffMainPage.aspx");
        }

        protected void btnReport_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("ReportPage.aspx");
        }

        protected void btnLogout_Click(object sender, ImageClickEventArgs e)
        {
            Session["user"] = null;
            Response.Redirect("LoginPage.aspx");
        }
    }
}